package com.khson.knows.portal.controller;


import com.github.pagehelper.PageInfo;
import com.khson.knows.portal.model.Question;
import com.khson.knows.portal.service.IQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author com.khson
 * @since 2021-08-23
 */
@RestController
@RequestMapping("/v1/questions")
public class QuestionController {
    @Autowired
    private IQuestionService questionService;

    @GetMapping("/my")
    public PageInfo<Question> getMyQuestions(
        //参数中可以使用一个注解获得当前登录用户的信息
        @AuthenticationPrincipal UserDetails user,
        Integer pageNum
    ){
        if(pageNum==null) pageNum = 1;
        return questionService.getMyQuestions(user.getUsername(),pageNum,8);
    }

}
